package com.ingrid.javi.activities;

import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;

import com.ingrid.javi.R;
import com.ingrid.javi.R.id;
import com.ingrid.javi.R.layout;
import com.ingrid.javi.model.DAO;

public class WishListActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.setContentView(R.layout.list_movie);

		ListView lvmovies = (ListView) findViewById(R.id.lvMovies);
		lvmovies.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> source, View row,
					int position, long id) {
				WishListActivity.this.OnItemClick(id);
			}
		});

		Cursor wishlistCursor;
		wishlistCursor = new DAO(this).listWish();
		this.bindMovies(lvmovies, wishlistCursor);
	}

	protected void OnItemClick(long id) {
		Intent intent = new Intent(this, DetailsWishActivity.class);
		intent.putExtra(DetailsWishActivity.EXTRA_SELECTED_ID, id);
		this.startActivity(intent);
	}

	private void bindMovies(ListView lvmovies, Cursor wishlistCursor) {
		lvmovies.setAdapter(new SimpleCursorAdapter(this,
				android.R.layout.simple_list_item_1, wishlistCursor,
				new String[] { DAO.COLUMN_TITLE },
				new int[] { android.R.id.text1 }));
	}
}
